package com.tarena.csmall.sso.mapper;

import cn.tedu.mall.common.pojo.admin.model.Admin;
import com.baomidou.dynamic.datasource.annotation.DS;
import java.util.List;
import org.apache.ibatis.annotations.Select;

@DS("admin")
public interface AdminMapper {
    @Select("select count(*) from ams_admin")
    public int countAdmin();
    @Select("select count(*) from ams_admin where username=#{username}")
    int countByUsername(String username);
    @Select("select * from ams_admin where username=#{username}")
    Admin findByUsername(String username);

    @Select("SELECT DISTINCT amp.value FROM\n" +
        "ams_permission amp \n" +
        "INNER JOIN ams_role_permission amrp\n" +
        "ON amp.id=amrp.permission_id\n" +
        "INNER JOIN ams_role amr\n" +
        "ON amrp.role_id=amr.id\n" +
        "INNER JOIN ams_admin_role amar\n" +
        "ON amar.role_id=amr.id\n" +
        "INNER JOIN ams_admin ama\n" +
        "ON ama.id=amar.admin_id\n" +
        "WHERE ama.username=#{username}")
    List<String> findPermissionsByUsername(String username);
}
